package com.hxx.day6;

import org.junit.Test;

import java.util.UUID;

public class TestDemo {
    public static void main(String[] args) {
        String s = "hello";
        String s1 = "world";
        //拼接字符串
        System.out.println(s.concat(s1));
        System.out.println(s+s1);
    }

    /**
     * 拼接字符串
     */
    @Test
    public void test1(){
        String join = String.join(";", "a", "b");
        System.out.println(join);
    }

    /**
     * 替换
     */
    @Test
    public void test2(){
        String string = UUID.randomUUID().toString();
        String replace = string.replace("-", "");
        System.out.println(replace);
    }
    /**
     * 去掉空格
     */
    @Test
    public void test3(){
        String str = "   h e llo   ";
        System.out.println(str.length());
        //去掉前后空格
        System.out.println(str.trim().length());
        //去掉所有空格
        System.out.println(str.replace(" ", "").length());
    }
    /**
     * 正则表达式
     */
    @Test
    public void test4(){
        String s1 = "asdd33dfsdaf33ddsd55fdd3dssf4343sdf455ddsdddh565gggh55ddhg";

        //将dd替换为"中"
        /*System.out.println(s1.replaceAll("dd", "中"));
        System.out.println(s1.replaceAll("d{2}", "中"));*/
        // \d 表示数字
        //System.out.println(s1.replaceAll("\\d", "中"));
        // \D 表示非数字
       // System.out.println(s1.replaceAll("\\D", "中"));

        // \W 表示非数字
        String a = "java.mysql;spring,html";
        System.out.println(a.replaceAll("\\W", "中"));
    }
}


























